package pl.easyshop.core.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Proxy;

import pl.easyshop.core.model.enums.ProductSortOrder;

/**
 * Category of product data model.
 * 
 * @author Pawel Witkowski
 */
@Entity
@Table(name="TBL_CATEGORY")
@Proxy(lazy=false)
public class CategoryModel extends AbstractBaseModel {

	/** Unique serialization identifier. */
	private static final long serialVersionUID = 4438348603621543938L;

	/** Category label (name). */
	@Column(name="label", length=64, nullable=false)
	private String label;
	
	/** Category description. */
	@Column(name="description", length=512, nullable=false)
	private String description;
	
	
	
	/** Value <code>true</code> means {@link #label} field is a resource code in properties file. */
	@Column(name="is_resource_code")
	private boolean resourceBoundleCode;
	
	/** If set <code>false</code> means category is not expected to display in front-end. */
	@Column(name="is_enabled")
	private boolean enabled;
	
	/** Parent category. */
	@ManyToOne
	@JoinColumn(name="parent_category_id")
	private CategoryModel parentCategory;

	/** Collection of sub categories. */
	@OneToMany(mappedBy="parentCategory", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
	private Set<CategoryModel> subCategories = new HashSet<CategoryModel>();
	
	/** Default sort products in category. */
	@Enumerated(EnumType.STRING)
	private ProductSortOrder defaultSortOrder;
	
	
	
	/**
	 * Add sub category.
	 * 
	 * @param category
	 */
	public void addSubCategory(CategoryModel category) {
		category.setParentCategory(this);
		subCategories.add(category);
	}


	/**
	 * Get label property value.
	 * @return the label
	 */
	public String getLabel() {
		return label;
	}


	/**
	 * Set label property value.
	 * @param label the label to set
	 */
	public void setLabel(String label) {
		this.label = label;
	}


	/**
	 * Get resourceBoundleCode property value.
	 * @return the resourceBoundleCode
	 */
	public boolean isResourceBoundleCode() {
		return resourceBoundleCode;
	}


	/**
	 * Set resourceBoundleCode property value.
	 * @param resourceBoundleCode the resourceBoundleCode to set
	 */
	public void setResourceBoundleCode(boolean resourceBoundleCode) {
		this.resourceBoundleCode = resourceBoundleCode;
	}


	/**
	 * Get enabled property value.
	 * @return the enabled
	 */
	public boolean isEnabled() {
		return enabled;
	}


	/**
	 * Set enabled property value.
	 * @param enabled the enabled to set
	 */
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}


	/**
	 * Get description property value.
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}


	/**
	 * Set description property value.
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}


	/**
	 * Get parentCategory property value.
	 * @return the parentCategory
	 */
	public CategoryModel getParentCategory() {
		return parentCategory;
	}


	/**
	 * Set parentCategory property value.
	 * @param parentCategory the parentCategory to set
	 */
	public void setParentCategory(CategoryModel parentCategory) {
		this.parentCategory = parentCategory;
	}


	/**
	 * Get subCategories property value.
	 * @return the subCategories
	 */
	public Set<CategoryModel> getSubCategories() {
		return subCategories;
	}


	/**
	 * Set subCategories property value.
	 * @param subCategories the subCategories to set
	 */
	public void setSubCategories(Set<CategoryModel> subCategories) {
		this.subCategories = subCategories;
	}


	/**
	 * Get defaultSortOrder property value.
	 * @return the defaultSortOrder
	 */
	public ProductSortOrder getDefaultSortOrder() {
		return defaultSortOrder;
	}


	/**
	 * Set defaultSortOrder property value.
	 * @param defaultSortOrder the defaultSortOrder to set
	 */
	public void setDefaultSortOrder(ProductSortOrder defaultSortOrder) {
		this.defaultSortOrder = defaultSortOrder;
	}




}
